import Cookies from "js-cookie";
import axios from "axios";

const state = {
    userInfo: {},
    localUserInfo: {},
    isMobile: false,
    boxCodeList: [],
    isLoading: false,
};
const mutations = {
    SET_USERINFO: (state, data) => {
        Cookies.set("userInfo", data);
        state.userInfo = JSON.parse(data);
    },
    REMOVE_USERINFO: (state, data) => {
        // 移除用户信息
        state.userInfo = {};
        Cookies.remove("userInfo");
    },

    // 更多信息写到localStorage中
    SET_LOCAL_USERINFO: (state, data) => {
        state.localUserInfo = JSON.parse(data);
        localStorage.setItem('localUserInfo', data);
    },
    CLEAR_LOCAL_USERINFO: (state, data) => {
        state.localUserInfo = {}
        localStorage.removeItem('localUserInfo');
    },
    // 判断当前是否是手机端
    SET_IS_MOBILE: (state, data) => {
        state.isMobile = data
    },

    // 已点击的窍列表
    BOX_CODE_LIST: (state, data) => {
        state.boxCodeList = data
    },

    // 更改isLoading的状态
    SET_LOADING_STATE: (state, data) => {
        state.isLoading = data
    },
};
const actions = {
    // 更新已点击的窍号数组
    setNewList({ commit, state }, boxCode) {
        //  includes  是否包包含某值
        const dd = state.boxCodeList.concat([boxCode])
        commit('BOX_CODE_LIST', [...new Set(dd)] )
    },
};

export default {
    namespaced: true,
    state,
    mutations,
    actions,
};